package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.common.log.annnotations.SpzxLog;
import com.atguigu.spzx.common.log.enums.OperateTypeEnum;
import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.result.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/brand")
@Tag(name = "商品品牌管理")
public class BrandController {
    @Resource
    BrandService brandService;
    @Operation(summary = "查询所有品牌")
    @GetMapping("list")
    public Result listAll(){
        List<Brand> list = brandService.listAll();
        return Result.ok(list);
    }
    @Operation(summary = "根据id查询品牌")
    @GetMapping("getById/{id}")
    public Result getById(@PathVariable("id")Long id){
        //删除时也可能前端需要得到删除的行数据
        Brand brand = brandService.getById(id);
        return Result.ok(brand);
    }
    @Operation(summary = "更新品牌")
    @PutMapping("update")
    public Result update(@RequestBody Brand brand){
        brandService.update(brand);
        return Result.ok();
    }
    @Operation(summary = "新增品牌")
    @PostMapping("save")
    public Result save(@RequestBody Brand brand){
        brandService.save(brand);
        return Result.ok();
    }
    @SpzxLog(title="商品品牌管理模块",operatorType = OperateTypeEnum.MANAGE,
            businessType = 2 , isRequestParamSave = true ,isResponseSave = false )
    @Operation(summary = "删除指定品牌")
    @DeleteMapping("deleteById/{id}")
    public Result deleteById(@PathVariable("id")Long id){
        //删除时也可能前端需要得到删除的行数据
        brandService.deleteById(id);
        return Result.ok();
    }
    @SpzxLog(title="商品品牌管理模块",operatorType = OperateTypeEnum.MOBILE,
    businessType = 0 , isRequestParamSave = true ,isResponseSave = true )
    @Operation(summary = "查询品牌分页数据")
    @GetMapping("list/{pageNum}/{pageSize}")
    public Result list(@PathVariable("pageNum") Integer pageNum ,
                            @PathVariable("pageSize")  Integer pageSize){
        PageInfo<Brand> page = brandService.list(pageNum,pageSize);
        return Result.ok(page);
    }
}
